<template>
  <div class="right-con">
    <div class="pl30 mb30 fs16"><b>密码重置</b></div>
    <el-form label-width="120px" style="width:50%;">
      <el-form-item label="原密码：">
        <el-input type="password" v-model="opsw"></el-input>
      </el-form-item>
      <el-form-item label="新密码：">
        <el-input type="password" v-model="npswa"></el-input>
      </el-form-item>
      <el-form-item label="确认新密码：">
        <el-input type="password" v-model="npswb"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="ml10" type="info" @click="onSubmit">确认修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import api from '../../assets/js/api'
  export default {
    name: "account",
    data() {
      return {
        pswData: new FormData(),
        opsw: '',
        npswa: '',
        npswb: ''
      }
    },
    methods: {
      onSubmit: function () {
        if (this.opsw == '') {
          this.$message.error('原密码不能为空！');
        } else if (this.npswa == '') {
          this.$message.error('新密码不能为空！');
        }else if(this.opsw ==this.npswa ){
          this.$message.error('不能与原密码一致！');
        } else if (this.npswb == '') {
          this.$message.error('确认新密码不能为空！');
        }else if(this.npswa  != this.npswb){
          this.$message.error('新密码两次输入不一致！');
        }else{
          this.pswData.append("old_password", this.opsw);
          this.pswData.append("new_password", this.npswa);
          this.pswData.append("confirm_password", this.npswb);
          console.log(this.pswData)
          api.fetch('/api/admin/account/reset',
            {
              method: 'post',
              data: this.pswData
            })
            .then(res => {
              this.$message({
                message: '密码重置成功',
                type: 'success'
              });
              this.$router.push('/login')
            }).catch((error) => {
            this.$message.error(error.response.data.message);
          })
        }
      }
    }
  }
</script>

<style scoped>

</style>
